{extend name="adminblue/base" /}
{block name="resources"/}
<script src="ADMIN_JS/art_dialog.source.js"></script>
<script src="ADMIN_JS/iframe_tools.source.js"></script>
<script src="ADMIN_JS/material_managedialog.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.config.js"></script>
<script type="text/javascript" charset="utf-8" src="ADMIN_JS/ueditor/ueditor.all.common.js"></script>
<link rel="stylesheet" type="text/css" href="ADMIN_CSS/defau.css">
<style type="text/css">
.article_head{margin:10px;}
.article_head label{float:left;margin-right:20px;width:120px;font-weight:normal;line-height: 32px;color:#333;font-size:13px; text-align: right;}
.article_head>div{overflow: hidden;}
.article_head>div .content_ue{width:100%;}
.textarea{width:70%;height:100px;max-width:70%;max-height:100px;}
.at_img{width:97%;height:135px;}
.at_btn{color: #FFF;background-color: #01B044;border-color: #01B044;font: normal 12px/20px "microsoft yahei";text-decoration: NONE; height: 35px; padding: 8px 10px;border: solid 1px;cursor: pointer;}
.class-logo{background-color: #F8F8F8;}
dd{margin-left: 0px;}
dl{margin:0px;}
input[type="radio"], input[type="checkbox"] { margin: 0 0 0;}
.required{color:red;margin-right:10px;}
.ar_top{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;}
.ar_bottom>div,.ar_top>div{clear: both;overflow: hidden;}
.article_head h3{margin: 0 0 10px 0;line-height: 30px;font-size: 14px;font-weight: bold;color: #333;padding-left: 10px;}
.ar_center{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;}
.ar_bottom{background:#F8F8F8; margin-top: 10px;padding: 10px;border: 1px solid #e9e9e9;margin-bottom:10px;}
.ke-inline-block{display: none;vertical-align: middle;zoom: 0;}
#image_file {width: 400px;}
input[type="file"]{border: none;}
</style>
{/block}
{block name="main"}
<div class="article_head">
	<div class="ar_top">
		<h3>常规信息</h3>
		<div>
			<label><span class="required">*</span>文章标题</label>
			<input id="title" class="input-common" type="text" name="title" style="width:70%;"/>
			<span class="error">请输入文章标题</span>
		</div>
		
		<div>
			<label>文章短标题</label>
			<input id="short_title" class="input-common" type="text" style="width:50%;"/>
		</div>
		
		<div>
			<label >文章标签</label>
			<input id="tag" class="input-common" type="text" style="width:50%;"/>
		</div>
		
		<div class="at_img">
			<label>文章标题图片</label>
			<div style="float:left;">
				<dl>
					<dd>
						<div class="class-logo"><p><img id="imgLogo"></p></div>
						<div class="upload-btn">
							<span>
								<input class="input-file" name="file_upload" id="uploadImg" type="file" onchange="imgUpload(this);">
							</span>
							<p><i class="fa fa-cloud-upload"></i>上传图片</p>
							<input type="hidden" id="Logo" /> 
						</div>
						<p class="hint">
							<span style="color:orange;">建议使用宽200像素-高60像素内的GIF或PNG透明图片；点击下方"提交"按钮后生效。</span>
						</p>
					</dd>
				</dl>
			</div>
		</div>

		<div>
			<label>文章作者</label>
			<input id="author" class="input-common" type="text" name="author"/>
		</div>
		
		<div>
			<label >文章来源</label>
			<input id="source" class="input-common" type="text"/>
		</div>
		
		<div>
			<label>文章来源链接</label>
			<input id="url" class="input-common" type="text"/>
		</div>
		
		<div>
			<label><span class="required">*</span>所属分类</label>
			<select id="class_id" class="select-common">
				<option value="0">请选择</option>
				{volist name="articleClassList['data']" id="vo"}
					{if condition="$vo.pid eq 0"}
					<option value="{$vo.class_id}">{$vo.name}</option>
					{volist name="articleClassList['data']" id="v1"}
						{if condition="$v1.pid eq $vo.class_id"}
						<option value="{$v1.class_id}">&nbsp;&nbsp;&nbsp;&nbsp;{$v1.name}</option>
						{/if}
					{/volist} 
					{/if}
				{/volist}
			</select>
			<span class="error">请选择分类</span>
		</div>

		<div>
			<label>文章关键字</label>
			<input id="keyword" type="text" class="input-common"/>
		</div>
		
		<div>
			<label>文章摘要</label>
			<textarea id="summary" rows="10" cols="10" class="textarea input-common"></textarea>
		</div>
		
	</div>
	
	<div class="ar_center">
		<h3>文章内容</h3>
		<div style="overflow: hidden;margin: 10px 0;">
			<label>文章内容</label>
<!-- 			<textarea id="content" name="g_body" style="width: 70%;height: 400px;overflow:hidden;visibility: hidden; display: none;"></textarea> -->
			<div style="float: left;">
				<script id="editor" type="text/plain" style="height: 400px;width:750px;"></script>
			</div>
		</div>
		<div style="overflow: hidden;margin: 10px 0;">
			<label>文章附件</label>
			<div style="float:left;">
				<dl>
					<dd>
						<div class="class-logo"><a id="filepath"><p id="p_file_upload_input"></p></a></div>
						<div class="upload-btn">
							<span>
								<input class="input-file" id="file_upload_input" name="file_upload" type="file">
								<input type="hidden" id="hidden_file_upload_input" />
							</span>
							<p><i class="fa fa-cloud-upload"></i>附件上传</p>
						</div>
					</dd>
				</dl>
			</div>
		</div>
		<div>
			<label>相关文章</label>
			<input id="article_id_array" class="input-common" type="text"/>
		</div>
	</div>
	
	<div class="ar_bottom">
		<h3>文章阐述</h3>
		<div>
			<label>推荐</label>
			<div style="margin-top:5px;float:left;"><input type="checkbox" id="commend_flag"/></div>
		</div>
		<div>
			<label>允许评论</label> 
			<div style="margin-top:5px;float:left;"><input type="checkbox" id="comment_flag"/></div>
		</div>
		<div>
			<label>文章排序</label>
			<input id="sort" type="number" class="input-common" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章点击量</label>
			<input id="click" type="number" class="input-common" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章评论数</label>
			<input id="comment_count" class="input-common" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
		<div>
			<label>文章分享数</label>
			<input id="share_count" class="input-common" type="number" min="0" onkeyup="value=value.replace(/[^\d+(\.\d+)?]/g,'')"/>
		</div>
	</div> 
	<div style="margin:auto;width:30%;">
		<button class="btn-common" onclick="save(1)" style="float:left;margin-right:15px;">发布文章</button>
		<button class="btn-common" onclick="save(2)" style="float:left;">发布并预览</button>
	</div>
</div>
{/block}
{block name="script"}
<script src="ADMIN_JS/ajax_file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/js/file_upload.js" type="text/javascript"></script>
<script src="__STATIC__/kindeditor/kindeditor-min.js" charset="utf-8"></script>
<script src="__STATIC__/kindeditor/lang/zh_cn.js" charset="utf-8"></script>
<script type="text/javascript">
$("#file_upload_input").live("change",function(){
	var data = { 'file_path' : UPLOADCOMMON };
	uploadFile("file_upload_input",data,function(res){
		if(res.code){
			$("#p_file_upload_input").text("文章附件");
			$("#filepath").attr("href","__UPLOAD__/"+res.data);
			$("#hidden_file_upload_input").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
});
// var KE;
// KindEditor.ready(function(K) {
// 	KE = K.create("textarea[name='g_body']",{
// 		items : [
// 			'source',
// 			'|',
// 			'fullscreen',
// 			'undo',
// 			'redo',
// 			'print',
// 			'cut',
// 			'copy',
// 			'paste',
// 			'plainpaste',
// 			'wordpaste',
// 			'|',
// 			'justifyleft',
// 			'justifycenter',
// 			'justifyright',
// 			'justifyfull',
// 			'insertorderedlist',
// 			'insertunorderedlist',
// 			'indent',
// 			'outdent',
// 			'subscript',
// 			'superscript',
// 			'|',
// 			'selectall',
// 			'clearhtml',
// 			'quickformat',
// 			'|',
// 			'formatblock',
// 			'fontname',
// 			'fontsize',
// 			'|',
// 			'forecolor',
// 			'hilitecolor',
// 			'bold',
// 			'italic',
// 			'underline',
// 			'strikethrough',
// 			'lineheight',
// 			'removeformat',
// 			'|',
// 			'image',
// 			'flash',
// 			'media',
// 			'table',
// 			'hr',
// 			'emoticons',
// 			'link',
// 			'unlink',
// 			'|',
// 			'about'
// 		],
// 		cssPath : "__STATIC__/kindeditor/themes/default/default.css",
// 		allowImageUpload : false,
// 		allowFlashUpload : false,
// 		allowMediaUpload : false,
// 		allowFileManager : false,
// 		syncType : "form",
// 		afterCreate : function() {
// 			var self = this;
// 			self.sync();
// 		},
// 		afterChange : function() {
// 			var self = this;
// 			self.sync();
// 		},
// 		afterBlur : function() {
// 			var self = this;
// 			self.sync();
// 		}
// 	});
// 	KE.appendHtml = function(id,val) {
// 		this.html(this.html()+ val);
// 		if (this.isCreated) {
// 			var cmd = this.cmd;
// 			cmd.range.selectNodeContents(cmd.doc.body).collapse(false);
// 			cmd.select();
// 		}
// 		return this;
// 	}
// });
var ue = UE.getEditor('editor',{
	toolbars : [
		[ 'source', // 源代码
		'bold', // 加粗
		'italic', // 斜体
		'underline', // 下划线
		'strikethrough', // 删除线
		'forecolor', // 字体颜色
		'backcolor', // 背景色
		'fontfamily', // 字体
		'fontsize', // 字号
		'paragraph', // 段落格式
		'justifyleft', // 居左对齐
		'justifycenter', // 居中对齐
		'justifyright', // 居右对齐
		'superscript', // 上标
		'blockquote', // 引用
		'selectall', // 全选
		'preview', // 预览
		'removeformat', // 清除格式
		'inserttable', // 插入表格
		'unlink', // 取消链接
		'insertrow', // 前插入行
		'insertcol', // 前插入列
		'mergeright', // 右合并单元格
		'mergedown', // 下合并单元格
		'deleterow', // 删除行
		'deletecol', // 删除列
		'splittorows', // 拆分成行
		'splittocols', // 拆分成列
		'splittocells', // 完全拆分单元格
		'deletecaption', // 删除表格标题
		'inserttitle', // 插入标题
		'mergecells', // 合并多个单元格
		'deletetable', // 删除表格
		'cleardoc', // 清空文档
		 'simpleupload', // 单图上传
		'insertimage', // 多图上传
		'link', // 超链接
		'emotion', // 表情
		'insertorderedlist', // 有序列表
		'insertunorderedlist', // 无序列表
		'fullscreen', // 全屏
		'directionalityltr', // 从左向右输入
		'directionalityrtl', // 从右向左输入
		'imagenone', // 默认
		'imageleft', // 左浮动
		'imageright', // 右浮动
		// 'attachment', // 附件
		'imagecenter', // 居中
		'lineheight', // 行间距
		'customstyle', // 自定义标题
		]]
});
$(function(){
	UE.getEditor('editor').addListener( 'ready', function() {
		if($("#content").val()){
			UE.getEditor('editor').setContent($("#content").val());
		}
	} );
})
function validation(){
	var title=$("#title");//文章标题
	var class_id=$("#class_id");//所属分类
	if(title.val() == ""){
		title.next().css("display","inline-block");
		title.focus();
		return false;
	}else{
		$('.error').hide();
	}
	
	if(class_id.val() == 0){
		class_id.next().css("display","inline-block");
		class_id.focus();
		return false;
	}else{
		$('.error').hide();
	}
	return true;
}


var flag = false;//防止重复提交
function save(type){
	if(!validation()){
		return;
	}
	var comment_flag=$('#comment_flag').is(':checked')?'1':'0';
	var commend_flag=$('#commend_flag').is(':checked')?'1':'0';
	var title=$("#title").val();
	var class_id=$("#class_id").val();
	var short_title=$("#short_title").val();
	var source=$("#source").val();
	var url=$("#url").val();
	var author=$("#author").val();
	var summary=$("#summary").val();
	var content = UE.getEditor('editor').getContent();
	//var content=$("#content").val();
//	var image=$("#imgLogo").attr("data-id");
    var image=$("#Logo").val();
	var keyword=$("#keyword").val();
	var article_id_array=$("#article_id_array").val();
	var click=$("#click").val();
	var sort=$("#sort").val();
	var tag=$("#tag").val();
	var comment_count=$("#comment_count").val();
	var share_count=$("#share_count").val();
	var attachment_path = $("#hidden_file_upload_input").val();
	if(flag){
		return;
	}
	flag = true;
	$.ajax({
		type:"post",
		url:"{:__URL('ADMIN_MAIN/Cms/addArticle')}",
		data:{
			'title':title,
			'class_id':class_id,
			'short_title':short_title,
			'source':source,
			'url':url,
			'author':author,
			'summary':summary,
			'content':content,
			'image':image,
			'keyword':keyword,
			'article_id_array':article_id_array,
			'click':click,
			'sort':sort,
			'commend_flag':commend_flag,
			'comment_flag':comment_flag,
			'attachment_path':attachment_path,
			'tag':tag,
			'comment_count':comment_count,
			'share_count':share_count,
			},
		success:function(data){
			if (data["code"] > 0) {
				showMessage('success', data["message"]);
				if(type==1){
					location.href=__URL("ADMIN_MAIN/cms/articlelist");
				}
				if(type==2){
					window.open(__URL("SHOP_MAIN/cms/articleclassinfo?article_id="+data['code']));
				}
			}else{
				showMessage('error', data["message"]);
				flag = false;
			}
		}
	});
}

function imgUpload(event) {
	var fileid = $(event).attr("id");
	var data = { 'file_path' : UPLOADCMS };
	uploadFile(fileid,data,function(res){
		if(res.code){
			$("#imgLogo").attr("src","__UPLOAD__/"+res.data);
			$("#Logo").val(res.data);
			showTip(res.message,"success");
		}else{
			showTip(res.message,"error");
		}
	});
}

/**
 * 删除文件
 * @param {Object} file_url
 * @param {Object} even
 */
function delete_file(file_url,even){
	$.ajax({
		type:"post",
		url:"{:__URL('ADMIN_MAIN/system/delete_file')}",
		data:{'file_url':file_url},
		async : true,
		dataType:'json',
		success:function(data){
			if (data['code']>0) {
				$( "#dialog" ).dialog({
					buttons: {
						"确定,#01B044": function() {
							$(this).dialog('close');
						}
					},
					contentText:"附件移除成功",
						time:1,
				});
				$(even).parent().empty();
			}else{
				$( "#dialog" ).dialog({
					buttons: {
						"确定,#e57373": function() {
							$(this).dialog('close');
						}
					},
					contentText:data['message'],
				});
			}
		}
	});
} 
</script>
{/block}